package org.wzy.springmvc.demo.mvc.action;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.wzy.springmvc.demo.service.INamedService;
import org.wzy.springmvc.demo.service.IService;
import org.wzy.springmvc.demo.service.IService2;
import org.wzy.springmvc.framework.annotation.MAutowired;
import org.wzy.springmvc.framework.annotation.MController;
import org.wzy.springmvc.framework.annotation.MRequestMapping;
import org.wzy.springmvc.framework.annotation.MRequestParam;
import org.wzy.springmvc.framework.annotation.MResponseBody;
import org.wzy.springmvc.framework.servlet.MModelAndView;

@MController
@MRequestMapping("/web")
public class FirstAction {

	@MAutowired
	private IService service;

	@MAutowired
	private IService2 service2;

	@MAutowired(value = "myName")
	private INamedService namedService;

	@MResponseBody
	@MRequestMapping("/query/.*.json")
	public MModelAndView query(HttpServletRequest request, HttpServletResponse response, 
			@MRequestParam("name") String name) throws IOException {
		response.getWriter().write("get params name = " + name + "\n");
		
		Map<String, Object> map = new HashMap<>();
		map.put("name", name);
		
		MModelAndView mv = new MModelAndView("first.pgml", map);
		return mv;
	}
}
